package com.grj.park.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.grj.park.common.R;
import com.grj.park.domain.ChargingStations;
import com.grj.park.domain.Investors;
import com.grj.park.service.ChargingStationsService;
import com.grj.park.service.InvestorsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("chargingStations")
public class ChargingStationsController {

    private final ChargingStationsService chargingStationsService;

    @GetMapping
    public R<List<ChargingStations>> getChargingStations(){
        return R.ok(chargingStationsService.list());
    }

    @PostMapping
    public R<?> saveChargingStationsService(@RequestBody ChargingStations chargingStations){
        LambdaQueryWrapper<ChargingStations> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChargingStations::getStationName, chargingStations.getStationName());
        ChargingStations one = chargingStationsService.getOne(queryWrapper);
        if (one != null){
            return R.fail("充电桩名字已存在");
        }
        chargingStationsService.save(chargingStations);
        return R.okMsg("添加充电桩成功");
    }
}
